package org.minos.edit.controller
{
	import flash.events.Event;
	import org.aswing.geom.IntDimension;
	import org.aswing.JFrame;
	import org.minos.edit.EditFacate;
	import org.minos.edit.view.components.SceneTable;
	import org.minos.edit.view.components.SelectAssetsPane;
	import org.minos.edit.view.TableMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * 选择场景方法
	 * @author ...
	 */
	public class SelectSceneCommand extends SimpleCommand
	{
		
		override public function execute( notification : INotification ) : void
		{
			super.execute( notification );
			//
			var table : SceneTable = facade.retrieveMediator( TableMediator.NAME ).getViewComponent() as SceneTable;
			
			//create 
			var dialog : JFrame = new JFrame( null , "场景列表" , true );
			var pane : SelectAssetsPane = new SelectAssetsPane( table.getItems() , [ "" ] , [ "名称" , "子菜单" ] , [ "label" , "children" ] );
			pane.setPreferredSize( new IntDimension( 600 , 400 ) );
			dialog.setContentPane( pane );
			
			pane.getOkButton().addActionListener( __onOk );
			pane.getCancelButton().addActionListener( __onCancel );
			
			//dialog
			dialog.pack();
			dialog.show();
			sendNotification( EditFacate.POSITION , dialog );
			
		// ----- event methods ----- //
			
			function __onOk( e : Event ) : void
			{
				if ( notification.getBody() )
				{
					//设置添加面板的子菜单文本childrenTf
					if ( notification.getBody().tf )
						notification.getBody().tf.setText( pane.getSelectedVOs() );
					//设置当前场景vo.children
					if ( notification.getBody().vo )
						notification.getBody().vo[notification.getBody().type] = pane.getSelectedVOs();
				}
				dialog.dispose();
			}
			
			function __onCancel( e : Event ) : void
			{
				dialog.dispose();
			}
			
		}
	}

}